<?php
class NewsAction extends CommonAction {
	
	public function add() {
		$newsCatalog_condition['status'] = 1 ;		
		$this->assign("newscatalogList",$this->CommonSimplequery($newsCatalog_condition,'news_catalog',0));		
		$this->display ();
	}

	
	public function saveNews(){

		$id = $_REQUEST['id'];		
		$data ["title"] = $_REQUEST ['title'];
		$data ["content"] = stripslashes($_REQUEST ['editorcontent']);		
		$data ["status"] = 1;
		$data ["author"] = $_REQUEST ['author'];
		$data ["rel"] = $_REQUEST ['rel'];		
		
		$data ["summary"] = $_REQUEST ['summary'];		
		$data["publishnewsindex"] = $_REQUEST['publishnewsindex'] ;
		$data["publishrecommend"] = $_REQUEST['publishrecommend'] ;
		$data["publishcatalog"] = $_REQUEST['publishcatalog'] ;
		//图片
		if( $_FILES['image']['name'] != ''){				
			$imgName = $this->_upload();
			$data["imageurl_small"] = "s_".$imgName ;
			$data["imageurl_big"] = "m_".$imgName ;
		}
		//新闻分类
		$data["news_catalog_id"] = $_REQUEST['newscatalog'] ;		
		$model = M ( "News" );		
		//新增
		if ( empty($id) ){
			$data ["createdate"] = date('Y-m-d H:i:s',time());
			$data ["statusdate"] = date('Y-m-d H:i:s',time());
			$save_result = $model->add($data) ;		
			$this->resultHandle($save_result,"新增新闻成功！","新增新闻失败！");
		}
		//修改
		else{
			$condition['id'] = $id ;
			$data ["statusdate"] = date('Y-m-d H:i:s',time());			
			$update_result = $model->where($condition)->data($data)->save();					
			$this->resultHandle($update_result,"修改新闻成功！","修改新闻失败！");
		}
	}
	
	
	public function edit(){		
		$condition['id'] = $_REQUEST['id'];
		$newsCatalog_condition['status'] = 1 ;		
		$this->assign("newscatalogList",$this->CommonSimplequery($newsCatalog_condition,'news_catalog',0));		
		$this->assign( "vo" , $this->CommonSimplequery($condition, "news",1));
		$this->display('./Tpl/default/News/add.html');
	}

	

}
?>